import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
import React from "react";
import SecondaryLayout from "../../compoents/secondary-layout";
import classes from "./addToken.module.less";
import ScrollView from "../../compoents/scroll-view";
import { CustomSwitch } from "../../compoents/styled";
import { useMount, useReactive } from "ahooks";
import useServices from "../../hooks/useRequest";
import { accountCoin, accountCoinShow } from "../../api/wallet";
import { useSelector } from "react-redux";
import { matchTheme } from "../../utils";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
function AddToken() {
    var state = useReactive({
        data: []
    });
    var theme = useSelector(function(st) {
        return st.app.theme;
    });
    var services = useServices({
        accountCoinShow: accountCoinShow,
        accountCoin: accountCoin
    });
    var changeShow = function(coin, index) {
        var nextShow = coin.isShow == 1 ? 0 : 1;
        state.data[index].isShow = nextShow;
        services.accountCoinShow({
            coinId: coin.coinId,
            isShow: nextShow
        }, false).catch(function() {
            state.data[index].isShow = nextShow == 1 ? 0 : 1;
        });
    };
    var getCoin = function() {
        var _ref = _async_to_generator(function() {
            return _ts_generator(this, function(_state) {
                try {
                    services.accountCoin(undefined, false).then(function(res) {
                        state.data = res.data;
                    });
                } catch (e) {}
                return [
                    2
                ];
            });
        });
        return function getCoin() {
            return _ref.apply(this, arguments);
        };
    }();
    useMount(function() {
        getCoin();
    });
    return /*#__PURE__*/ _jsx(SecondaryLayout, {
        title: "Add token",
        className: classes.add_token,
        children: /*#__PURE__*/ _jsx("div", {
            className: classes.wrap,
            children: /*#__PURE__*/ _jsx(ScrollView, {
                scrollY: true,
                children: /*#__PURE__*/ _jsx("div", {
                    children: state.data.map(function(item, index) {
                        return /*#__PURE__*/ _jsxs("div", {
                            className: classes.coin,
                            children: [
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.info,
                                    children: [
                                        /*#__PURE__*/ _jsx("img", {
                                            className: classes.img,
                                            src: item.coinLogo
                                        }),
                                        /*#__PURE__*/ _jsx("div", {
                                            className: classes.name,
                                            children: item.coinName
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.switch,
                                    children: [
                                        /*#__PURE__*/ _jsx("img", {
                                            src: item.type === "ETH" ? matchTheme(theme, {
                                                light: require("../../assets/icons/ethPrimary.svg"),
                                                dark: require("../../assets/icons/dark/eth.svg")
                                            }) : matchTheme(theme, {
                                                light: require("../../assets/icons/bscPrimary.svg"),
                                                dark: require("../../assets/icons/dark/bnb.svg")
                                            }),
                                            className: classes.ico
                                        }),
                                        /*#__PURE__*/ _jsx(CustomSwitch, {
                                            checked: item.isShow == 1,
                                            onChange: function() {
                                                changeShow(item, index);
                                            }
                                        })
                                    ]
                                })
                            ]
                        }, item.coinId);
                    })
                })
            })
        })
    });
}
export default AddToken;

 //# sourceMappingURL=index.js.map